﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.OleDb;
using System.Linq;
using System.Text;

namespace Spider.Dual_coloredBall
{
    /// <summary>
    /// 类GameResults。
    /// </summary>
    [Serializable]
    public partial class GameResults
    {
        public GameResults()
        {
        }

        #region Model

        private int _id;
        private int? _gameyear = 0;
        private string _gamenum;
        private DateTime? _gamedate;
        private int? _redone = 0;
        private int? _redtwo = 0;
        private int? _redthree = 0;
        private int? _redfour = 0;
        private int? _redfive = 0;
        private int? _redsix = 0;
        private int? _blueseven = 0;
        private int? _salesvolume = 0;

        /// <summary>
        /// 
        /// </summary>
        public int ID
        {
            set { _id = value; }
            get { return _id; }
        }

        /// <summary>
        /// 年度
        /// </summary>
        public int? GameYear
        {
            set { _gameyear = value; }
            get { return _gameyear; }
        }

        /// <summary>
        /// 期号
        /// </summary>
        public string GameNum
        {
            set { _gamenum = value; }
            get { return _gamenum; }
        }

        /// <summary>
        /// 日期
        /// </summary>
        public DateTime? GameDate
        {
            set { _gamedate = value; }
            get { return _gamedate; }
        }

        /// <summary>
        /// 红球1
        /// </summary>
        public int? RedOne
        {
            set { _redone = value; }
            get { return _redone; }
        }

        /// <summary>
        /// 红球2
        /// </summary>
        public int? RedTwo
        {
            set { _redtwo = value; }
            get { return _redtwo; }
        }

        /// <summary>
        /// 红球3
        /// </summary>
        public int? RedThree
        {
            set { _redthree = value; }
            get { return _redthree; }
        }

        /// <summary>
        /// 红球4
        /// </summary>
        public int? RedFour
        {
            set { _redfour = value; }
            get { return _redfour; }
        }

        /// <summary>
        /// 红球5
        /// </summary>
        public int? RedFive
        {
            set { _redfive = value; }
            get { return _redfive; }
        }

        /// <summary>
        /// 红球6
        /// </summary>
        public int? RedSix
        {
            set { _redsix = value; }
            get { return _redsix; }
        }

        /// <summary>
        /// 蓝球7
        /// </summary>
        public int? BlueSeven
        {
            set { _blueseven = value; }
            get { return _blueseven; }
        }

        /// <summary>
        /// 销量
        /// </summary>
        public int? SalesVolume
        {
            set { _salesvolume = value; }
            get { return _salesvolume; }
        }

        #endregion Model


        #region  Method

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public GameResults(int ID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append(
                "select ID,GameYear,GameNum,GameDate,RedOne,RedTwo,RedThree,RedFour,RedFive,RedSix,BlueSeven,SalesVolume ");
            strSql.Append(" FROM [GameResults] ");
            strSql.Append(" where ID=@ID ");
            OleDbParameter[] parameters =
            {
                new OleDbParameter("@ID", OleDbType.Integer, 4)
            };
            parameters[0].Value = ID;

            DataSet ds = DbHelperOleDb.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["ID"] != null && ds.Tables[0].Rows[0]["ID"].ToString() != "")
                {
                    this.ID = int.Parse(ds.Tables[0].Rows[0]["ID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["GameYear"] != null && ds.Tables[0].Rows[0]["GameYear"].ToString() != "")
                {
                    this.GameYear = int.Parse(ds.Tables[0].Rows[0]["GameYear"].ToString());
                }
                if (ds.Tables[0].Rows[0]["GameNum"] != null)
                {
                    this.GameNum = ds.Tables[0].Rows[0]["GameNum"].ToString();
                }
                if (ds.Tables[0].Rows[0]["GameDate"] != null && ds.Tables[0].Rows[0]["GameDate"].ToString() != "")
                {
                    this.GameDate = DateTime.Parse(ds.Tables[0].Rows[0]["GameDate"].ToString());
                }
                if (ds.Tables[0].Rows[0]["RedOne"] != null && ds.Tables[0].Rows[0]["RedOne"].ToString() != "")
                {
                    this.RedOne = int.Parse(ds.Tables[0].Rows[0]["RedOne"].ToString());
                }
                if (ds.Tables[0].Rows[0]["RedTwo"] != null && ds.Tables[0].Rows[0]["RedTwo"].ToString() != "")
                {
                    this.RedTwo = int.Parse(ds.Tables[0].Rows[0]["RedTwo"].ToString());
                }
                if (ds.Tables[0].Rows[0]["RedThree"] != null && ds.Tables[0].Rows[0]["RedThree"].ToString() != "")
                {
                    this.RedThree = int.Parse(ds.Tables[0].Rows[0]["RedThree"].ToString());
                }
                if (ds.Tables[0].Rows[0]["RedFour"] != null && ds.Tables[0].Rows[0]["RedFour"].ToString() != "")
                {
                    this.RedFour = int.Parse(ds.Tables[0].Rows[0]["RedFour"].ToString());
                }
                if (ds.Tables[0].Rows[0]["RedFive"] != null && ds.Tables[0].Rows[0]["RedFive"].ToString() != "")
                {
                    this.RedFive = int.Parse(ds.Tables[0].Rows[0]["RedFive"].ToString());
                }
                if (ds.Tables[0].Rows[0]["RedSix"] != null && ds.Tables[0].Rows[0]["RedSix"].ToString() != "")
                {
                    this.RedSix = int.Parse(ds.Tables[0].Rows[0]["RedSix"].ToString());
                }
                if (ds.Tables[0].Rows[0]["BlueSeven"] != null && ds.Tables[0].Rows[0]["BlueSeven"].ToString() != "")
                {
                    this.BlueSeven = int.Parse(ds.Tables[0].Rows[0]["BlueSeven"].ToString());
                }
                if (ds.Tables[0].Rows[0]["SalesVolume"] != null && ds.Tables[0].Rows[0]["SalesVolume"].ToString() != "")
                {
                    this.SalesVolume = int.Parse(ds.Tables[0].Rows[0]["SalesVolume"].ToString());
                }
            }
        }

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int ID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from [GameResults]");
            strSql.Append(" where ID=@ID ");

            OleDbParameter[] parameters =
            {
                new OleDbParameter("@ID", OleDbType.Integer, 4)
            };
            parameters[0].Value = ID;

            return DbHelperOleDb.Exists(strSql.ToString(), parameters);
        }


        /// <summary>
        /// 增加一条数据
        /// </summary>
        public void Add()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into [GameResults] (");
            strSql.Append(
                "GameYear,GameNum,GameDate,RedOne,RedTwo,RedThree,RedFour,RedFive,RedSix,BlueSeven,SalesVolume)");
            strSql.Append(" values (");
            strSql.Append(
                "@GameYear,@GameNum,@GameDate,@RedOne,@RedTwo,@RedThree,@RedFour,@RedFive,@RedSix,@BlueSeven,@SalesVolume)");
            OleDbParameter[] parameters =
            {
                new OleDbParameter("@GameYear", OleDbType.Integer, 4),
                new OleDbParameter("@GameNum", OleDbType.VarChar, 255),
                new OleDbParameter("@GameDate", OleDbType.Date),
                new OleDbParameter("@RedOne", OleDbType.Integer, 4),
                new OleDbParameter("@RedTwo", OleDbType.Integer, 4),
                new OleDbParameter("@RedThree", OleDbType.Integer, 4),
                new OleDbParameter("@RedFour", OleDbType.Integer, 4),
                new OleDbParameter("@RedFive", OleDbType.Integer, 4),
                new OleDbParameter("@RedSix", OleDbType.Integer, 4),
                new OleDbParameter("@BlueSeven", OleDbType.Integer, 4),
                new OleDbParameter("@SalesVolume", OleDbType.Integer, 4)
            };
            parameters[0].Value = GameYear;
            parameters[1].Value = GameNum;
            parameters[2].Value = GameDate;
            parameters[3].Value = RedOne;
            parameters[4].Value = RedTwo;
            parameters[5].Value = RedThree;
            parameters[6].Value = RedFour;
            parameters[7].Value = RedFive;
            parameters[8].Value = RedSix;
            parameters[9].Value = BlueSeven;
            parameters[10].Value = SalesVolume;

            DbHelperOleDb.ExecuteSql(strSql.ToString(), parameters);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update [GameResults] set ");
            strSql.Append("GameYear=@GameYear,");
            strSql.Append("GameNum=@GameNum,");
            strSql.Append("GameDate=@GameDate,");
            strSql.Append("RedOne=@RedOne,");
            strSql.Append("RedTwo=@RedTwo,");
            strSql.Append("RedThree=@RedThree,");
            strSql.Append("RedFour=@RedFour,");
            strSql.Append("RedFive=@RedFive,");
            strSql.Append("RedSix=@RedSix,");
            strSql.Append("BlueSeven=@BlueSeven,");
            strSql.Append("SalesVolume=@SalesVolume");
            strSql.Append(" where ID=@ID ");
            OleDbParameter[] parameters =
            {
                new OleDbParameter("@GameYear", OleDbType.Integer, 4),
                new OleDbParameter("@GameNum", OleDbType.VarChar, 255),
                new OleDbParameter("@GameDate", OleDbType.Date),
                new OleDbParameter("@RedOne", OleDbType.Integer, 4),
                new OleDbParameter("@RedTwo", OleDbType.Integer, 4),
                new OleDbParameter("@RedThree", OleDbType.Integer, 4),
                new OleDbParameter("@RedFour", OleDbType.Integer, 4),
                new OleDbParameter("@RedFive", OleDbType.Integer, 4),
                new OleDbParameter("@RedSix", OleDbType.Integer, 4),
                new OleDbParameter("@BlueSeven", OleDbType.Integer, 4),
                new OleDbParameter("@SalesVolume", OleDbType.Integer, 4),
                new OleDbParameter("@ID", OleDbType.Integer, 4)
            };
            parameters[0].Value = GameYear;
            parameters[1].Value = GameNum;
            parameters[2].Value = GameDate;
            parameters[3].Value = RedOne;
            parameters[4].Value = RedTwo;
            parameters[5].Value = RedThree;
            parameters[6].Value = RedFour;
            parameters[7].Value = RedFive;
            parameters[8].Value = RedSix;
            parameters[9].Value = BlueSeven;
            parameters[10].Value = SalesVolume;
            parameters[11].Value = ID;

            int rows = DbHelperOleDb.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int ID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from [GameResults] ");
            strSql.Append(" where ID=@ID ");
            OleDbParameter[] parameters =
            {
                new OleDbParameter("@ID", OleDbType.Integer, 4)
            };
            parameters[0].Value = ID;

            int rows = DbHelperOleDb.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public void GetModel(int ID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append(
                "select ID,GameYear,GameNum,GameDate,RedOne,RedTwo,RedThree,RedFour,RedFive,RedSix,BlueSeven,SalesVolume ");
            strSql.Append(" FROM [GameResults] ");
            strSql.Append(" where ID=@ID ");
            OleDbParameter[] parameters =
            {
                new OleDbParameter("@ID", OleDbType.Integer, 4)
            };
            parameters[0].Value = ID;

            DataSet ds = DbHelperOleDb.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["ID"] != null && ds.Tables[0].Rows[0]["ID"].ToString() != "")
                {
                    this.ID = int.Parse(ds.Tables[0].Rows[0]["ID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["GameYear"] != null && ds.Tables[0].Rows[0]["GameYear"].ToString() != "")
                {
                    this.GameYear = int.Parse(ds.Tables[0].Rows[0]["GameYear"].ToString());
                }
                if (ds.Tables[0].Rows[0]["GameNum"] != null)
                {
                    this.GameNum = ds.Tables[0].Rows[0]["GameNum"].ToString();
                }
                if (ds.Tables[0].Rows[0]["GameDate"] != null && ds.Tables[0].Rows[0]["GameDate"].ToString() != "")
                {
                    this.GameDate = DateTime.Parse(ds.Tables[0].Rows[0]["GameDate"].ToString());
                }
                if (ds.Tables[0].Rows[0]["RedOne"] != null && ds.Tables[0].Rows[0]["RedOne"].ToString() != "")
                {
                    this.RedOne = int.Parse(ds.Tables[0].Rows[0]["RedOne"].ToString());
                }
                if (ds.Tables[0].Rows[0]["RedTwo"] != null && ds.Tables[0].Rows[0]["RedTwo"].ToString() != "")
                {
                    this.RedTwo = int.Parse(ds.Tables[0].Rows[0]["RedTwo"].ToString());
                }
                if (ds.Tables[0].Rows[0]["RedThree"] != null && ds.Tables[0].Rows[0]["RedThree"].ToString() != "")
                {
                    this.RedThree = int.Parse(ds.Tables[0].Rows[0]["RedThree"].ToString());
                }
                if (ds.Tables[0].Rows[0]["RedFour"] != null && ds.Tables[0].Rows[0]["RedFour"].ToString() != "")
                {
                    this.RedFour = int.Parse(ds.Tables[0].Rows[0]["RedFour"].ToString());
                }
                if (ds.Tables[0].Rows[0]["RedFive"] != null && ds.Tables[0].Rows[0]["RedFive"].ToString() != "")
                {
                    this.RedFive = int.Parse(ds.Tables[0].Rows[0]["RedFive"].ToString());
                }
                if (ds.Tables[0].Rows[0]["RedSix"] != null && ds.Tables[0].Rows[0]["RedSix"].ToString() != "")
                {
                    this.RedSix = int.Parse(ds.Tables[0].Rows[0]["RedSix"].ToString());
                }
                if (ds.Tables[0].Rows[0]["BlueSeven"] != null && ds.Tables[0].Rows[0]["BlueSeven"].ToString() != "")
                {
                    this.BlueSeven = int.Parse(ds.Tables[0].Rows[0]["BlueSeven"].ToString());
                }
                if (ds.Tables[0].Rows[0]["SalesVolume"] != null && ds.Tables[0].Rows[0]["SalesVolume"].ToString() != "")
                {
                    this.SalesVolume = int.Parse(ds.Tables[0].Rows[0]["SalesVolume"].ToString());
                }
            }
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select * ");
            strSql.Append(" FROM [GameResults] ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperOleDb.Query(strSql.ToString());
        }

        #endregion  Method
    }
}
